/*	
 *				
 *					ISNW ---- It is a war.It is not warcraft!
 *
 *
 *					Author:					zhoukeli(haxixi_keli)
 *					Filename:				AnimateMeshSceneNode.h
 *					CreateTime:				2008/12/29
 *					ModifyTime:				2008/12/29
 *
 */

#ifndef __ISNW_ANIMATE_MESH_SCENE_NODE_H__
#define __ISNW_ANIMATE_MESH_SCENE_NODE_H__

#include "include/IAnimateMeshSceneNode.h"

namespace ISNW
{
namespace scene
{
	class AnimateMeshSceneNode : public IAnimateMeshSceneNode
	{
	public:
		AnimateMeshSceneNode(ISceneManager* sm,ISceneNode* parent,IAnimateMesh* mesh,s32 id,
			core::vector3df pos,core::vector3df rotate,core::vector3df scale)
			:IAnimateMeshSceneNode(sm,parent,mesh,id,pos,rotate,scale)
			,AnimateMesh(0)
			,FPS(60)
			,lastTime(0)
			,currFrame(0)
			,totalFrame(0)
			,AnimateType(E_AT_LOOP)
		{
			setmesh(mesh);

			totalFrame = AnimateMesh->getframenum();
		}

	public:
		void setmesh(IAnimateMesh* mesh)
		{
			if(AnimateMesh)
			{
				AnimateMesh->drop();
			}

			if(mesh)
			{
				mesh->grab();
				AnimateMesh = mesh;
			}
		}

		const IAnimateMesh* getmesh() const
		{
			return AnimateMesh;
		}

		void onAnimate(u32 Time);

		void render();

		void setFPS(u32 fps)
		{
			FPS = fps;
		}

		u32 getFPS() const
		{
			return FPS;
		}

		u32 getCurrFrame() const
		{
			return currFrame;
		}

		void buildCurrFrame(u32 Time);

		void setAnimateType(E_ANIMATE_TYPE t)
		{
			AnimateType = t;
		}

		void onRegisterSceneNode();

	protected:
		IAnimateMesh*	AnimateMesh;

		u32 FPS;

		u32 lastTime;

		u32 currFrame;

		u32 totalFrame;

		E_ANIMATE_TYPE AnimateType;
	};
} // end namespace scene
} // end namespace ISNW
#endif